package com.birdcage.gamemanagers;

import java.util.ArrayList;
import java.util.Iterator;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

///Singleton
///This will detect all physics logic of the game.
public class GraphicsManager
{
    ///Private member
    private ArrayList<GraphicsElement> m_units = new ArrayList<GraphicsElement>();
    private SpriteBatch m_renderer = new SpriteBatch();
    private boolean m_enable = true;
    
    ///Singleton Implement
    static public GraphicsManager GetInstance()
    {
        if (m_instance == null)
        {
            m_instance = new GraphicsManager();
        }       
        return m_instance;
    }
    
    private GraphicsManager(){};
    private static GraphicsManager m_instance = null;
    
    ///Public Method
    public void Update()
    {
        if (m_enable && !m_units.isEmpty())
        {
            Iterator<GraphicsElement> iter = m_units.iterator();
            GetRenderer().begin();
            while(iter.hasNext())
            {
                GraphicsElement unit = iter.next();
                unit.Update(GetRenderer());
            }
            GetRenderer().end();
 
        }
    }
    
    public void AddElement(GraphicsElement elem)
    {
        m_units.add(elem);
    }
    
    public void RemoveElement(GraphicsElement elem)
    {
        if (elem != null)
        {
            m_units.remove(elem);
        }
    }

    public SpriteBatch GetRenderer()
    {
        return m_renderer;
    }

    public void SetEnable(boolean m_enable)
    {
        this.m_enable = m_enable;
    }

    public boolean GetEnable()
    {
        return m_enable;
    }
}
